﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class UserLogin : System.Web.UI.Page
{
    protected void Page_PreInit(object sender, EventArgs e)
    {
        Page.Theme = BLL.Common.GetWSMThemes();
    }
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnLogin_Click(object sender, EventArgs e)
    {
        if (Session["Code"].ToString().Trim() == TextBox1.Text.Trim())
        {
            DataRow u = new BLL.USERS().CheckLogin(txtUserCode.Text.Trim(), txtPwd.Text.Trim());
            if (u != null)
            {
                string[] res ={ u["USERS_CODE"].ToString(), u["USERS_NAME"].ToString(), u["USERS_UGCODE"].ToString() };
                Session["Users"] = res;
                Hashtable ht1 = new Hashtable();
                Hashtable ht2 = new Hashtable();
                DataSet ds = new BLL.USERS().GetModuleList(res[0], "UserName");//获取菜单
                DataTable dt1, dt2;
                dt1 = ds.Tables[0];
                dt2 = ds.Tables[1];
                for (int i = 0; i < dt1.Rows.Count; i++)
                {
                    ht1.Add(dt1.Rows[i]["FUNC_CODE"].ToString(), dt1.Rows[i]["FUNC_CODE"].ToString());
                }
                Session["Functions"] = ht1;
                Session["Operates"] = dt2;
                Response.Redirect("index.aspx");
            }
            else
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), "", "alert('登录失败');", true);
            }
        }
        else
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "", "alert('验证码错误');", true);
        }
        txtUserCode.Text = "";
        txtPwd.Text = "";
        
    }
    protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {
        this.ImageButton1.ImageUrl = "VolidCode.ashx";
    }
}
